/*
* Copyright (c) 2009 by Thomas Busey and Ruj Akavipat
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*     * Redistributions of source code must retain the above copyright
*       notice, this list of conditions and the following disclaimer.
*     * Redistributions in binary form must reproduce the above copyright
*       notice, this list of conditions and the following disclaimer in the
*       documentation and/or other materials provided with the distribution.
*     * Neither the name of the Experteyes nor the
*       names of its contributors may be used to endorse or promote products
*       derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY Thomas Busey and Ruj Akavipat ''AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL Thomas Busey and Ruj Akavipat BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
 * ProjectSelectPanel.java
 *
 * Created on September 19, 2007, 9:36 PM
 */
package eyetrackercalibrator.gui;

import eyetrackercalibrator.framemanaging.FrameLoadingListener;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.event.ActionListener;
import java.io.File;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

/**
 * @author  SQ
 */
public class ProjectSelectPanel extends javax.swing.JPanel {

    // Storing the last directory selected by browse action
    File lastSelectedLocation = new File(".");

    /** Creates new form ProjectSelectPanel */
    public ProjectSelectPanel() {
        initComponents();
    }

    void checkIntegerInput(String input) {
        try {
            if (input.length() > 0) {
                Integer.parseInt(input);
            }
        } catch (NumberFormatException e) {
            JOptionPane.showMessageDialog(this,
                    "<html>Require integers for width and height</html>");
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel2 = new javax.swing.JLabel();
        eyeDirectoryTextField = new javax.swing.JTextField();
        browseEyeViewButton = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        screenDirectoryTextField = new javax.swing.JTextField();
        browseScreenViewButton = new javax.swing.JButton();
        loadEyeImageButton = new javax.swing.JButton();
        reloadEyeInfoButton = new javax.swing.JButton();
        synchronizeButton = new javax.swing.JButton();
        calibrateButton = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        eyeFrameSynchPositionLabel = new javax.swing.JLabel();
        screenFrameSynchPositionLabel = new javax.swing.JLabel();
        eyeFrameLoadedProgressBar = new javax.swing.JProgressBar();
        screenFrameLoadedProgressBar = new javax.swing.JProgressBar();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        browseScreenInfoButton = new javax.swing.JButton();
        screenInfoDirectoryTextField = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        eyeInfoDirectoryTextField = new javax.swing.JTextField();
        browseEyeInfoButton = new javax.swing.JButton();
        cleanDataButton = new javax.swing.JButton();
        markTrialButton = new javax.swing.JButton();
        jLabel15 = new javax.swing.JLabel();
        fullScreenDirectoryTextField = new javax.swing.JTextField();
        browseScreenFullViewButton = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jLabel12 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        fullScreenWidthTextField = new javax.swing.JTextField();
        monitorWidthTextField = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        fullScreenHeightTextField = new javax.swing.JTextField();
        monitorHeightTextField = new javax.swing.JTextField();
        loadScreenImageButton = new javax.swing.JButton();
        reloadScreenInfoButton = new javax.swing.JButton();
        exportButton = new javax.swing.JButton();
        computeScreenIlluminationButton = new javax.swing.JButton();
        exportMoviesButton = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        commentTextPane = new javax.swing.JTextPane();

        jLabel2.setText("Eye view location");

        browseEyeViewButton.setText("Browse");
        browseEyeViewButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                browseEyeViewButtonActionPerformed(evt);
            }
        });

        jLabel3.setText("Screen view location");

        browseScreenViewButton.setText("Browse");
        browseScreenViewButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                browseScreenViewButtonActionPerformed(evt);
            }
        });

        loadEyeImageButton.setText("Load Images");
        loadEyeImageButton.setActionCommand("Load Eye Images");

        reloadEyeInfoButton.setText("Reload Information");
        reloadEyeInfoButton.setActionCommand("Reload Eye Information");

        synchronizeButton.setText("Synchronize");

        calibrateButton.setText("Calibrate");

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Synchronize"));

        jLabel1.setText("Eye Frame:");

        jLabel4.setText("Screen Frame:");

        eyeFrameSynchPositionLabel.setText("0");

        screenFrameSynchPositionLabel.setText("0");

        org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .add(jLabel1)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(eyeFrameSynchPositionLabel)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 53, Short.MAX_VALUE)
                .add(jLabel4)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(screenFrameSynchPositionLabel)
                .add(46, 46, 46))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(20, Short.MAX_VALUE)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel1)
                    .add(jLabel4)
                    .add(eyeFrameSynchPositionLabel)
                    .add(screenFrameSynchPositionLabel))
                .addContainerGap())
        );

        eyeFrameLoadedProgressBar.setString("N/A");
        eyeFrameLoadedProgressBar.setStringPainted(true);

        screenFrameLoadedProgressBar.setString("N/A");
        screenFrameLoadedProgressBar.setStringPainted(true);

        jLabel7.setText("Eye Frame Loaded:");

        jLabel8.setText("Screen Frame Loaded:");

        browseScreenInfoButton.setText("Browse");
        browseScreenInfoButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                browseScreenInfoButtonActionPerformed(evt);
            }
        });

        jLabel5.setText("Screen info location");

        jLabel6.setText("Eye info location");

        browseEyeInfoButton.setText("Browse");
        browseEyeInfoButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                browseEyeInfoButtonActionPerformed(evt);
            }
        });

        cleanDataButton.setText("Clean Data");

        markTrialButton.setText("Mark Trials");

        jLabel15.setText("Screen full view location");

        browseScreenFullViewButton.setText("Browse");
        browseScreenFullViewButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                browseScreenFullViewButtonActionPerformed(evt);
            }
        });

        jLabel12.setText("Screen full size:");

        jLabel9.setText("Monitor size:");

        jLabel11.setText("Width");

        jLabel13.setText("Width");

        monitorWidthTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                monitorWidthTextFieldKeyTyped(evt);
            }
        });

        jLabel10.setText("x Height");

        jLabel14.setText("x Height");

        org.jdesktop.layout.GroupLayout jPanel2Layout = new org.jdesktop.layout.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel2Layout.createSequentialGroup()
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(jLabel12)
                    .add(jLabel9))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jLabel11)
                    .add(jLabel13))
                .add(2, 2, 2)
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                    .add(fullScreenWidthTextField)
                    .add(monitorWidthTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 49, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jLabel10)
                    .add(jLabel14))
                .add(2, 2, 2)
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                    .add(fullScreenHeightTextField)
                    .add(monitorHeightTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 47, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel2Layout.createSequentialGroup()
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel11)
                    .add(jLabel10)
                    .add(monitorWidthTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(monitorHeightTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel9))
                .add(17, 17, 17)
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel12)
                    .add(jLabel13)
                    .add(fullScreenWidthTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel14)
                    .add(fullScreenHeightTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 24, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
        );

        loadScreenImageButton.setText("Load Images");
        loadScreenImageButton.setActionCommand("Load Screen Images");

        reloadScreenInfoButton.setText("Reload Information");
        reloadScreenInfoButton.setActionCommand("Reload Screen Information");

        exportButton.setText("Export Data");

        computeScreenIlluminationButton.setText("Compute Screen Illumination");

        exportMoviesButton.setText("Export Movies");

        commentTextPane.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Comment"));
        jScrollPane1.setViewportView(commentTextPane);

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                        .addContainerGap()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                            .add(jLabel6)
                            .add(jLabel2)
                            .add(jLabel3)
                            .add(jLabel5)
                            .add(jLabel15))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                                .add(eyeInfoDirectoryTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 659, Short.MAX_VALUE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(browseEyeInfoButton))
                            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                                    .add(org.jdesktop.layout.GroupLayout.LEADING, fullScreenDirectoryTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 659, Short.MAX_VALUE)
                                    .add(org.jdesktop.layout.GroupLayout.LEADING, screenDirectoryTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 659, Short.MAX_VALUE)
                                    .add(org.jdesktop.layout.GroupLayout.LEADING, eyeDirectoryTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 659, Short.MAX_VALUE))
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                        .add(browseEyeViewButton)
                                        .add(browseScreenViewButton))
                                    .add(browseScreenFullViewButton)))
                            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                                .add(screenInfoDirectoryTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 659, Short.MAX_VALUE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(browseScreenInfoButton))))
                    .add(layout.createSequentialGroup()
                        .addContainerGap()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                            .add(jLabel8)
                            .add(jLabel7))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                            .add(screenFrameLoadedProgressBar, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 507, Short.MAX_VALUE)
                            .add(eyeFrameLoadedProgressBar, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 507, Short.MAX_VALUE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(layout.createSequentialGroup()
                                .add(loadEyeImageButton)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(reloadEyeInfoButton))
                            .add(layout.createSequentialGroup()
                                .add(loadScreenImageButton)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(reloadScreenInfoButton)))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED))
                    .add(layout.createSequentialGroup()
                        .add(10, 10, 10)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(layout.createSequentialGroup()
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(computeScreenIlluminationButton)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(synchronizeButton)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(calibrateButton)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(cleanDataButton)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(markTrialButton)
                                .add(6, 6, 6)
                                .add(exportButton)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                                .add(exportMoviesButton))
                            .add(layout.createSequentialGroup()
                                .add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                                .add(jPanel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 104, Short.MAX_VALUE))
                    .add(layout.createSequentialGroup()
                        .addContainerGap()
                        .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 853, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(browseEyeViewButton)
                    .add(eyeDirectoryTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel2))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(browseScreenViewButton)
                    .add(screenDirectoryTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel3))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(fullScreenDirectoryTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(browseScreenFullViewButton)
                    .add(jLabel15))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(browseEyeInfoButton)
                    .add(jLabel6)
                    .add(eyeInfoDirectoryTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(browseScreenInfoButton)
                    .add(screenInfoDirectoryTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel5))
                .add(20, 20, 20)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jPanel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(18, 18, 18)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(loadEyeImageButton)
                    .add(reloadEyeInfoButton)
                    .add(jLabel7)
                    .add(eyeFrameLoadedProgressBar, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(26, 26, 26)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(loadScreenImageButton)
                    .add(reloadScreenInfoButton)
                    .add(jLabel8)
                    .add(screenFrameLoadedProgressBar, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 143, Short.MAX_VALUE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(computeScreenIlluminationButton)
                    .add(synchronizeButton)
                    .add(calibrateButton)
                    .add(cleanDataButton)
                    .add(markTrialButton)
                    .add(exportButton)
                    .add(exportMoviesButton))
                .addContainerGap())
        );

        loadEyeImageButton.getAccessibleContext().setAccessibleName("Load Eye Images");
        reloadEyeInfoButton.getAccessibleContext().setAccessibleName("Reload Eye Information");
        loadScreenImageButton.getAccessibleContext().setAccessibleName("Load Screen Images");
        reloadScreenInfoButton.getAccessibleContext().setAccessibleName("Reload Screen Information");
    }// </editor-fold>//GEN-END:initComponents
    private void monitorWidthTextFieldKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_monitorWidthTextFieldKeyTyped
        checkIntegerInput((monitorWidthTextField.getText() + evt.getKeyChar()).trim());
}//GEN-LAST:event_monitorWidthTextFieldKeyTyped

    private void browseEyeInfoButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseEyeInfoButtonActionPerformed
        browseDirectory(eyeInfoDirectoryTextField);
    }//GEN-LAST:event_browseEyeInfoButtonActionPerformed

    private void browseScreenInfoButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseScreenInfoButtonActionPerformed
        browseDirectory(screenInfoDirectoryTextField);
    }//GEN-LAST:event_browseScreenInfoButtonActionPerformed

    private void browseScreenViewButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseScreenViewButtonActionPerformed
        browseDirectory(screenDirectoryTextField);
    }//GEN-LAST:event_browseScreenViewButtonActionPerformed

    private void browseEyeViewButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseEyeViewButtonActionPerformed
        browseDirectory(eyeDirectoryTextField);
    }//GEN-LAST:event_browseEyeViewButtonActionPerformed

    private void browseScreenFullViewButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseScreenFullViewButtonActionPerformed
        browseDirectory(fullScreenDirectoryTextField);
}//GEN-LAST:event_browseScreenFullViewButtonActionPerformed

    private void browseDirectory(JTextField targetField) {
        // Set text box with directory that user chose.
        JFileChooser fileChooser = new JFileChooser();
        fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        if (targetField.getText().length() > 1) {
            // Get current selection from text field
            fileChooser.setSelectedFile(new File(targetField.getText()));
        } else {
            // Otherwise open to latest location if there is nothing in the field text
            fileChooser.setSelectedFile(lastSelectedLocation);
        }

        if (fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
            // Save current position
            lastSelectedLocation = fileChooser.getSelectedFile();
            targetField.setText(lastSelectedLocation.getAbsolutePath());
        }
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton browseEyeInfoButton;
    private javax.swing.JButton browseEyeViewButton;
    private javax.swing.JButton browseScreenFullViewButton;
    private javax.swing.JButton browseScreenInfoButton;
    private javax.swing.JButton browseScreenViewButton;
    private javax.swing.JButton calibrateButton;
    private javax.swing.JButton cleanDataButton;
    private javax.swing.JTextPane commentTextPane;
    private javax.swing.JButton computeScreenIlluminationButton;
    private javax.swing.JButton exportButton;
    private javax.swing.JButton exportMoviesButton;
    private javax.swing.JTextField eyeDirectoryTextField;
    private javax.swing.JProgressBar eyeFrameLoadedProgressBar;
    private javax.swing.JLabel eyeFrameSynchPositionLabel;
    private javax.swing.JTextField eyeInfoDirectoryTextField;
    private javax.swing.JTextField fullScreenDirectoryTextField;
    private javax.swing.JTextField fullScreenHeightTextField;
    private javax.swing.JTextField fullScreenWidthTextField;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton loadEyeImageButton;
    private javax.swing.JButton loadScreenImageButton;
    private javax.swing.JButton markTrialButton;
    private javax.swing.JTextField monitorHeightTextField;
    private javax.swing.JTextField monitorWidthTextField;
    private javax.swing.JButton reloadEyeInfoButton;
    private javax.swing.JButton reloadScreenInfoButton;
    private javax.swing.JTextField screenDirectoryTextField;
    private javax.swing.JProgressBar screenFrameLoadedProgressBar;
    private javax.swing.JLabel screenFrameSynchPositionLabel;
    private javax.swing.JTextField screenInfoDirectoryTextField;
    private javax.swing.JButton synchronizeButton;
    // End of variables declaration//GEN-END:variables
    /**
     * Add listener to listen to "Load Image", "Reload Information",
     * "Synchronize", "Calibrate", "Clean data" and "Mark trials" commands
     */
    public void addActionListener(ActionListener listener) {
        loadEyeImageButton.addActionListener(listener);
        reloadEyeInfoButton.addActionListener(listener);
        loadScreenImageButton.addActionListener(listener);
        reloadScreenInfoButton.addActionListener(listener);
        synchronizeButton.addActionListener(listener);
        calibrateButton.addActionListener(listener);
        cleanDataButton.addActionListener(listener);
        markTrialButton.addActionListener(listener);
        exportButton.addActionListener(listener);
        computeScreenIlluminationButton.addActionListener(listener);
        exportMoviesButton.addActionListener(listener);
    }

    @Override
    public void setEnabled(boolean enabled) {
        super.setEnabled(enabled);
        Component[] components = getComponents();
        for (int i = 0; i < components.length; i++) {
            components[i].setEnabled(enabled);
        }
    }

    public FrameLoadingListener getEyeFrameLoadingListener() {
        return new FrameLoadingListener() {

            public void update(String updateText, int totalLoad, int totalFrame) {
                eyeFrameLoadedProgressBar.setString(updateText);
                eyeFrameLoadedProgressBar.setMaximum(totalFrame);
                eyeFrameLoadedProgressBar.setValue(totalLoad);
            }
        };
    }

    public String getEyeFrameDirectory() {
        return eyeDirectoryTextField.getText();
    }

    public String getScreenFrameDirectory() {
        return screenDirectoryTextField.getText();
    }

    public String getFullScreenFrameDirectory() {
        return fullScreenDirectoryTextField.getText();
    }

    public String getScreenInfoDirectory() {
        return screenInfoDirectoryTextField.getText();
    }

    public String getEyeInfoDirectory() {
        return eyeInfoDirectoryTextField.getText();
    }

    public void setEyeFrameDirectory(String dir) {
        eyeDirectoryTextField.setText(dir);
    }

    public void setScreenFrameDirectory(String dir) {
        screenDirectoryTextField.setText(dir);
    }

    public void setFullScreenFrameDirectory(String dir) {
        fullScreenDirectoryTextField.setText(dir);
    }

    public void setScreenInfoDirectory(String dir) {
        screenInfoDirectoryTextField.setText(dir);
    }

    public void setEyeInfoDirectory(String dir) {
        eyeInfoDirectoryTextField.setText(dir);
    }

    public FrameLoadingListener getScreenFrameLoadingListener() {
        return new FrameLoadingListener() {

            public void update(String updateText, int totalLoad, int totalFrame) {
                screenFrameLoadedProgressBar.setString(updateText);
                screenFrameLoadedProgressBar.setMaximum(totalFrame);
                screenFrameLoadedProgressBar.setValue(totalLoad);
            }
        };
    }

    public void setSynchronizeFrames(int eyeFrameNumber, int screenFrameNumber) {
        eyeFrameSynchPositionLabel.setText(String.valueOf(eyeFrameNumber));
        screenFrameSynchPositionLabel.setText(String.valueOf(screenFrameNumber));
    }

    public String getSynchronizedEyeFrame() {
        return eyeFrameSynchPositionLabel.getText();

    }

    public String getSynchronizedScreenFrame() {
        return screenFrameSynchPositionLabel.getText();
    }

    public Dimension getMonitorDimension() {
        if (monitorWidthTextField.getText().length() > 0 && monitorHeightTextField.getText().length() > 0) {
            return new Dimension(
                    Integer.parseInt(monitorWidthTextField.getText()),
                    Integer.parseInt(monitorHeightTextField.getText()));
        } else {
            return null;
        }
    }

    public void setMonitorDimension(String width, String height) {
        monitorWidthTextField.setText(width);
        monitorHeightTextField.setText(height);
    }

    public void setFullScreenDimension(String width, String height) {
        fullScreenHeightTextField.setText(height);
        fullScreenWidthTextField.setText(width);
    }

    public Dimension getFullScreenDimension() {
        if (fullScreenHeightTextField.getText().length() > 0 && fullScreenWidthTextField.getText().length() > 0) {
            return new Dimension(
                    Integer.parseInt(fullScreenWidthTextField.getText()),
                    Integer.parseInt(fullScreenHeightTextField.getText()));
        } else {
            return null;
        }
    }

    public void setEyeLoadButtonsEnable(boolean b) {
        loadEyeImageButton.setEnabled(b);
        reloadEyeInfoButton.setEnabled(b);
    }

    public void setScreenLoadButtonsEnable(boolean b) {
        loadScreenImageButton.setEnabled(b);
        reloadScreenInfoButton.setEnabled(b);
        computeScreenIlluminationButton.setEnabled(b);
    }
    
    public void setComment(String comment){
        this.commentTextPane.setText(comment);
    }
    
    public String getComment(){
        return this.commentTextPane.getText();
    }
}
